package plus.lgx.textsearcher.searcher.extender;

import plus.lgx.textsearcher.config.SearcherConfig;

/**
 * Class name: MaxExtender
 *
 * Create time: 12/17/22 8:29 PM
 *
 * @author lgx
 * @version 1.0
 */
public class MaxExtender extends Extender {
    public MaxExtender(SearcherConfig config) {
        super(config);
    }

    private final int maxExtendCharsCount = config.maxExtendCharsCount;

    @Override
    public String extend() {
        index.set(Math.min(index.get() + maxExtendCharsCount, off - 1));
        return content.substring(Math.max(index.get() - maxExtendCharsCount, 0), index.get()).trim();
    }

}
